<template>
    <div class="goods-list">

        <router-link class="goods-item" v-for="item in goodslist" :key="item.img_url" to="/home/goodsinfo" tag="div">
            <img :src="item.img_url" alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.sell_price}}</span>
                    <span class="old">{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.stock_quantity }}件</span>
                </p>
            </div>
        </router-link>

        <!-- api 渲染 商品列表 -->
        <!-- <div class="goods-item" v-for="item in goodslist" :key="item.id"> -->
            <!-- <img :src="item.img_url" alt=""> -->
            <!-- <h1 class="title">{{item.title}}</h1> -->
            <!-- <div class="info"> -->
                <!-- <p class="price"> -->
                    <!-- <span class="now">￥{{item.sell_price}}</span> -->
                    <!-- <span class="old">￥{{item.market_price}}</span> -->
                <!-- </p> -->
                <!-- <p class="sell"> -->
                    <!-- <span>热卖中</span> -->
                    <!-- <span>剩{{ item.stock_quantity }}件</span> -->
                <!-- </p> -->
            <!-- </div> -->
        <!-- </div> -->
        <!-- 加载更多按钮 -->
        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
export default {
  data() {
    // data 是往自己组建内部，挂载一些私有的数据
    return {
      pageindex: 1, // 分页的页数
      goodslist: [
        // 存放商品列表的数组
        {
          title:
            "小米8 青春版 4GB+64GB 潮流镜面渐变色，2400万自拍旗舰",
          img_url: require("../../images/goodslist01.jpg"),
          sell_price: "1399",
          market_price: "1599",
          stock_quantity: "49"
        },
        {
          title:
            "小米8 SE 4GB+64GB AI 超感光双摄，三星 AMOLED 屏幕",
          img_url: require("../../images/goodslist02.jpg"),
          sell_price: "1649",
          market_price: "1799",
          stock_quantity: "666"
        },
        {
          title:
            "小米MIX 2S 8GB+256GB 骁龙845 年度旗舰处理器",
          img_url: require("../../images/goodslist03.jpg"),
          sell_price: "3599",
          market_price: "3999",
          stock_quantity: "199"
        },
        {
          title:
            "小米MIX 2 全陶瓷尊享版 全面屏2.0，Unibody 全陶瓷",
          img_url: require("../../images/goodslist04.jpg"),
          sell_price: "2699",
          market_price: "4699",
          stock_quantity: "88"
        },
        {
          title:
            "小米6X 4GB+32GB 全索尼相机，骁龙660 AIE处理器",
          img_url: require("../../images/goodslist05.jpg"),
          sell_price: "1299",
          market_price: "1499",
          stock_quantity: "123"
        }
      ]
    };
  },
  created() {
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      //   // 获取商品列表
      //   this.$http
      //     .get("api/getgoods?pageindex=" + this.pageindex)
      //     .then(result => {
      //       if (result.body.status === 0) {
      //         // this.goodslist = result.body.message;
      //         this.goodslist = this.goodslist.concat(result.body.message);
      //       }
      //     });
    },
    getMore() {
      // this.pageindex++
      // this.getGoodsList();
    }
  },
  
};
</script>

<style lang="scss" scoped>
.goods-list {
  display: flex;
  flex-wrap: wrap; // 换行
  padding: 6px;
  justify-content: space-between; // 左右对齐
  .goods-item {
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 4px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 294px;
    .title {
      word-break: break-all;
      font-size: 14px;
    }
    img {
      width: 100%;
    }
    .info {
      background-color: #eee;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          color: red;
          font-weight: bold;
          font-size: 16px;
        }
        .old {
          text-decoration: line-through; // 贯穿线
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
        font-size: 12px;
      }
    }
  }
}
</style>
